package com.bookmanagement.mapper;

import com.bookmanagement.VO.BookRecordVO;
import com.bookmanagement.entity.Book;
import com.bookmanagement.entity.BorrowRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author skyjay
 */
@Mapper
public interface BorrowRecordMapper {


    @Select("select * from borrow_record where user_id = #{userId} and is_deleted = 0")
    List<BookRecordVO> getBatchRecordByUserId(Integer userId);

    @Update("update borrow_record set is_deleted = 1 where id=#{id}")
    void deleteRecord(Integer id);

    @Select("select * from borrow_record where user_id = #{id} and is_deleted = 0 and status=0")
    List<BookRecordVO> getCurrentRecord(Integer id);

    @Insert("insert into borrow_record(user_id,book_id,borrow_time,due_time,status) values(#{userId},#{bookId},#{borrowTime},#{dueTime},#{status})")
    void addRecord(BorrowRecord borrowRecord);

    @Update("update borrow_record set status = #{status} where book_id = #{id}")
    void setStatus(Integer id, int i);
}
